package org.eclipse.gittab.player.internal.midi;

import org.eclipse.emf.ecore.EObject;

public class Util {

	/**
	 * Shamelessly copied from Xtext's EcoreUtil2. Didn't want to have a
	 * dependency on Xtext just because of this superb function.
	 * 
	 * @param <T>
	 * @param ele
	 * @param type
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public static <T extends EObject> T getContainerOfType(EObject ele,
			Class<T> type) {
		if (type.isAssignableFrom(ele.getClass()))
			return (T) ele;
		if (ele.eContainer() != null)
			return getContainerOfType(ele.eContainer(), type);
		return null;
	}

}
